Micron Document
Deavmi's coding shack


Displaying Rendered • View rawDownload

new_docs/content/documentation/structs.md 4f104ea5ebeb83e0201ca91abe676a955ac57a8c (4f104ea5) Text, 1.48 KB

title: Structs
tags: [structs]
date: 2021-05-31

Introduction

What are structs? In T a Struct is a user-defined type which associates several fields toghether however, unlike C, structs in T can have a set of functions associated with them as well.

The syntax for declaring a struct with name T383838<name>, and some fields T383838<field1>, T383838<field2> with the types T383838<type1>, T383838type2> respectively is as follows:

T282828
struct <name>
{
<type1> <field1>;
<type2> <field2>;
}

Note: Assignments to these variables within the struct's body is not allowed.

Example

Perhaps we want a simple struct that associates a name, age and gender together to represent a Person, then we can declare such a struct as follows:

T282828
struct Person
{
char* name;
ubyte age;
ubyte gender;
}


Member functions

One can also define a struct to have certain functions associated with it that will operate on its data without having to refer to it directly in the source code. The syntac for a member function with return type T383838<returnType>, name T383838<funcName>, of a struct is (along with our previous struct) as follows:

T282828
struct <name>
{
<type1> <field1>;
<type2> <field2>;

<returnType> <funcName>()
{
return <instanceOfReturnType>;
}
}

Example

TODO: Add some text here describing it

T282828
struct structTest
{
int j;
int j;

void pdsjhfjdsf(int j)
{

}

void pdsjhfjdsf(int j)
{

}
}

Served by rngit 1.5.0 - Generated in 0.05s